<?php

interface IObservable
{
	function addObserver($observer);
}


class field implements IObservable {
	
	protected $value;
	public $name;
	public $beforechange;
	public $afterchange;
	//public $defaultvalue;
	private $observers = array();
	
	function addObserver($observer) {
		$this->observers[] = $observer;
	}
	
	function __set($name, $value) {
		if ($name == "value") {
			foreach($this->observers as $obs)
				$obs->observable_before_changed($this, $value);
			$this->value = $value;
			foreach($this->observers as $obs)
				$obs->observable_after_changed($this, $value);
		}
	}
	
	function __get($name) {
		if ($name == "value") { return $this->value;}
	}
}
?>

